package com.mrjy.maintain.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mrjy.common.entity.DistributorTeamInfo;
import com.mrjy.common.entity.ServiceStationInfo;
import com.mrjy.common.entity.UserInfo;
import com.mrjy.common.enums.ResultEnum;
import com.mrjy.common.exception.InnerException;
import com.mrjy.common.util.GlobalConstant;
import com.mrjy.maintain.bo.IServiceStationInfoBo;
import com.mrjy.maintain.dto.ServiceStationParamDTO;

@Controller
@RequestMapping("/maintain/serviceStationInfo")
public class ServiceStationInfoController {

	@Resource
	private IServiceStationInfoBo serviceStationInfoBo;

	/**
	 * 服务站分页查询
	 * 
	 * @param serviceStationInfo
	 * @return
	 */
	@RequestMapping("/stationList")
	@ResponseBody
	public Object stationList(ServiceStationInfo serviceStationInfo,HttpSession session) {
		return serviceStationInfoBo.queryPageServiceStationInfo(serviceStationInfo,session);
	}

	/**
	 * 根据地址查询服务站列表 个人中心--服务站咨询 --根据省份、城市和县区查询服务站咨询列表
	 * 
	 * @param serviceStationInfo
	 *            serviceStationInfo.province serviceStationInfo.city
	 *            serviceStationInfo.county
	 * @author csshui isUse=true
	 * @return
	 */
	@RequestMapping("/stationListByDist")
	@ResponseBody
	public Object stationListByDist(ServiceStationInfo serviceStationInfo){
		return serviceStationInfoBo.queryServiceStationListNoPage(serviceStationInfo);
	}
	
	/**
	 * 根据id查询
	 * @param id
	 * @return
	 */
	@RequestMapping("/queryById")
	@ResponseBody
	public Object queryById(int id) {
		return serviceStationInfoBo.queryById(id);
	}

	/**
	 * 服务站名称验证
	 * @param serviceStationInfo
	 * @return
	 */
	@RequestMapping("/stationValidate")
	@ResponseBody
	public Object stationValidate(ServiceStationInfo serviceStationInfo,String stid){
		return serviceStationInfoBo.serviceStationValidate(serviceStationInfo,stid);
	}
	
	/**
	 * 添加服务站信息
	 * @param serviceStationInfo
	 * @return
	 */
	@RequestMapping(value = "/addServiceStation", method = RequestMethod.POST)
	@ResponseBody
	public Object addServiceStation(ServiceStationInfo serviceStationInfo,HttpSession session) {
		return serviceStationInfoBo.txInsert(serviceStationInfo,session);
	}

	/**
	 * 修改服务站信息
	 * @param serviceStationInfo
	 * @return
	 */
	@RequestMapping("/updateServiceStation")
	@ResponseBody
	public Object updateServiceStation(ServiceStationInfo serviceStationInfo,HttpSession session) {
		return serviceStationInfoBo.txUpdateById(serviceStationInfo,session);
	}

	/**
	 * 修改服务站状态（禁用、启用）
	 * @param serviceStationInfo
	 * @return
	 */
	@RequestMapping("/updateDisableFlag")
	@ResponseBody
	public Object updateDisableFlag(ServiceStationInfo serviceStationInfo,HttpSession session) {
		return serviceStationInfoBo.txUpdateDisableFlag(serviceStationInfo,session);
	}

	/**
	 * 批量删除
	 * @param ids
	 * @return
	 */
	@RequestMapping("/deleteByIds")
	@ResponseBody
	public Object deleteByIds(int[] ids) {
		return serviceStationInfoBo.deleteByIds(ids);
	}

	/**
	 * 导出excel
	 * 
	 * @param accessLog
	 * @return
	 */
	@RequestMapping("/export")
	@ResponseBody
	public Object export(HttpServletResponse response, ServiceStationInfo serviceStationInfo,HttpSession session) {
		return serviceStationInfoBo.exportExl(serviceStationInfo,response,session);
	}
	
	/**
	 * 根据服务站id查询其团队成员(废弃)
	 * @param stationId
	 * @return
	 */
	@RequestMapping("/queryTeamById")
	@ResponseBody
	public Object queryTeamById(ServiceStationInfo serviceStationInfo){
		List<DistributorTeamInfo> list = serviceStationInfoBo.queryTeamByStationId(serviceStationInfo);
		return list;
	}
	
	/**
	 * 查询服务站总记录数
	 * @return
	 */
	@RequestMapping("/getTotal")
	@ResponseBody
	public Object getTotal(ServiceStationInfo serviceStationInfo){
		return serviceStationInfoBo.getTotal(serviceStationInfo);
	}
	
	
	/**
	 * 验证手机号是否被注册
	 * @param mobilePhone
	 * @return
	 */
	@RequestMapping("/checkMobilePhoneExist")
	@ResponseBody
	public Object checkMobilePhoneExist(ServiceStationInfo serviceStationInfo){
		return serviceStationInfoBo.checkMobilePhoneExist(serviceStationInfo);
	}
	
	/**
	 * 1.6.9.3 查询服务站列表
	 * @param rows 条数
	 * @param page 页数
	 * @param province 省份
	 * @param session
	 * @return
	 */
	@RequestMapping("/station/list")
	@ResponseBody
	public Object queryStationPage(ServiceStationParamDTO dto,HttpSession session) {	
		UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if(null == loginUser ){
			throw new InnerException(ResultEnum.NOT_LOGIN);
		}
		return serviceStationInfoBo.queryStationPage(dto);
    }
	
	@RequestMapping("/station/calling_num/plus")
	@ResponseBody
	public Object addCallingNumById(Integer id,HttpSession session) {	
		UserInfo loginUser = (UserInfo) session.getAttribute(GlobalConstant.USER_INFO);
		if(null == loginUser ){
			throw new InnerException(ResultEnum.NOT_LOGIN);
		}
		return serviceStationInfoBo.txAddCallingNumById(id,loginUser.getId());
    }
	
}
